import { createRouter, createWebHistory, createWebHashHistory, RouteRecordRaw } from "vue-router";
import Home from '../views/Home.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      requireAuth: true,
    },
    children: [
      {
        path: '/word', // word简历模版
        name: 'Word',
        component: () => import('@/views/Word.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/word/:id', // word简历模版详情
        name: 'WordDetail',
        component: () => import('@/views/WordDetail.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/moban', // 在线简历模版
        name: 'Moban',
        component: () => import('@/views/Moban.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/moban/:id', // 在线简历模版详情
        name: 'MobanDetail',
        component: () => import('@/views/MobanDetail.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/quan', // 职业圈
        name: 'Quan',
        component: () => import('@/views/Quan.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/gonglue', // 简历攻略
        name: 'Gonelue',
        component: () => import('@/views/Gonelue.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/fanwen', // 简历范文
        name: 'Fanwen',
        component: () => import('@/views/Fanwen.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/mianshi', // 面试技巧
        name: 'Mianshi',
        component: () => import('@/views/Mianshi.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/zhichang', // 职场指南
        name: 'Zhichang',
        component: () => import('@/views/Zhichang.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/a/:id', // 文章详情
        name: 'Article',
        component: () => import('@/views/Article.vue'),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: '/about', // 关于我们
        name: 'About',
        component: () => import('@/views/About.vue'),
        meta: {
          requireAuth: false,
        }
      },
      {
        path: '/contact', // 联系我们
        name: 'Contact',
        component: () => import('@/views/Contact.vue'),
        meta: {
          requireAuth: false,
        }
      },
      {
        path: '/terms', // 服务条款
        name: 'Terms',
        component: () => import('@/views/Terms.vue'),
        meta: {
          requireAuth: false,
        }
      },
      {
        path: '/vip', // vip特权
        name: 'Vip',
        component: () => import('@/views/Vip.vue'),
        meta: {
          requireAuth: false,
        }
      },
      {
        path: '/user', // vip特权
        name: 'User',
        component: () => import('@/views/User.vue'),
        meta: {
          requireAuth: false,
        }
      },
      {
        path: '/order', // 我的订单
        name: 'Order',
        component: () => import('@/views/Order.vue'),
        meta: {
          requireAuth: false,
        }
      },
      {
        path: '/like', // 我喜欢的
        name: 'Like',
        component: () => import('@/views/Like.vue'),
        meta: {
          requireAuth: false,
        }
      },
      {
        path: '/setup', // 账户设置
        name: 'Setup',
        component: () => import('@/views/Setup.vue'),
        meta: {
          requireAuth: false,
        }
      },
    ]
  },
  {
    path: "/:catchAll(.*)",
    name: 'NotFount',
    component: () => import('@/components/error/404.vue'),
    meta: {
      requireAuth: false,
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  // history: createWebHashHistory(),
  routes
})

// 导航守卫判断本地是否有 token
router.beforeEach(async (to: any, from: any, next: any) => {
  // if (to.meta.requireAuth) {
  //   if (sessionStorage.getItem("_token") && sessionStorage.getItem("_token") != '') {
  //     next();
  //   } else {
  //     location.href = '/login';
  //   }
  // } else {
  //   next();
  // }
  console.log(to, from, next);
  next();
  // let title = to.mate.title
})

export default router
